﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://wubiyu.cnblogs.com">
<head>
    <title>_g() 方法</title>
    <link href="../../Theme/DomExtGray/gray.min.css" rel="Stylesheet" type="text/css" />
    <link href="PageModel.css" rel="Stylesheet" type="text/css" />
    <script type="text/javascript" src="../../domExt.min.js"></script>
</head>
<body>
    <div class="fun_title">
        _g(expression, [context])
    </div>
    <div class="fun_content">
        描述：选择器方法 ，可根据Id、标签名、样式名获取DOM对象。<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 当没有传入context参数时，将在整个DOM集合对象中查找，否则在相应的DOM集合中查找。</div>
    <div class="fun_title2">
        参数:
    </div>
    <div class="fun_content2">
        expression：<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #id：据给定的ID匹配一个元素,并将h.Default对象扩展到当前对象。<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tagName ：根据给定的元素名匹配所有元素。并将h.Default.DomCollectionFn对象扩展到当前对象。<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .className：根据样式名称匹配所有元素。并将h.Default.DomCollectionFn对象扩展到当前对象。<br />
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; >tagName：获取下级结点。并将h.Default.DomCollectionFn对象扩展到当前对象。 例如 g(">div"); 
        <br />
        [context]：<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 作为待查找的 DOM 元素集。当网页被嵌入ifarme 中时可以用window.parent.window.document获取上层文档的DOM对象。<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可以使用window.parent.widnow.functuon
        调用上层文档的JS方法。<br />
        <strong>Retrun:</strong><br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DOM对象<br />
        <br />
    </div>
    <div class="fun_title2">
        示例:
    </div>
    <div class="code">
        &lt;div id=&quot;div1&quot;&gt;&lt;div class=&#39;testclass&#39;&gt;testdiv&lt;/div&gt;&lt;/div&gt;
    </div>
    <input type="hidden" value="<div id='div1'><div class='testclass'>testdiv</div></div>"
        id="htmlcode">
    <div class="code">
        &lt;script type=&quot;text/javascript&quot;&gt;<br />
        &nbsp;&nbsp;&nbsp; var div1 = _g(&quot;#div1&quot;);&nbsp;&nbsp;&nbsp;
        <br />
        &nbsp;&nbsp;&nbsp; var <i>collObjects1=_g(&quot;div&quot;);</i><br />
        &nbsp;&nbsp;&nbsp; var <i>collObjects2=_g(&quot;.testclass&quot;,div1);</i><br />
        &nbsp;&nbsp;&nbsp; alert(div1.innerHTML);<br />
        &lt;/script&gt;</div>
    <input type="hidden" value=" var div1 = _g('#div1');  var collObjects1=_g('div');var collObjects2=_g('.testclass',div1);alert(div1.innerHTML);"
        id="jscode">
    <br />
    <h:btn onclick="run_click();">执行脚本</h:btn>
    <div id="htmltemp" style="display: none;">
    </div>
    <div id="d1">
        <div id="div2">
            testdiv</div>
    </div>
    <script type="text/javascript">
        function run_click() {
            var htmltemp = _g("#htmltemp");
            var htmlcode = _g("#htmlcode");
            htmltemp.innerHTML = htmlcode.value;
            var jscode = _g("#jscode");
            eval(jscode.value);
        }
    </script>
</body>
</html>
